#pragma once

#include "../core/event_loop.hpp"
#include <functional>
#include <unordered_map>
#include <csignal>

class SignalHandler {
public:
    using SignalCallback = std::function<void(int)>;

    SignalHandler(EventLoop& loop);
    ~SignalHandler();

    // 注册信号处理函数
    void registerSignal(int signum, SignalCallback callback);
    
    // 移除信号处理函数
    void removeSignal(int signum);

private:
    EventLoop& loop_;
    std::unordered_map<int, SignalCallback> callbacks_;
    static int signal_pipe_[2];
    
    static void handleSignal(int signum);
    void onSignal(int signum);
}; 